<?php
$host="localhost";
$username="root";
$pass_word="";
$db="SWGeekStore";
$Conn = mysql_connect( $host,$username,$pass_word) or die ("cannot connect");
mysql_query("SET NAMES utf8",$Conn);
mysql_select_db($db) or die("cannot connect to database"); 


if($_POST){
	
	
	$itemID = $_POST['itemID'];
	$itemName = $_POST['itemName'];
	$price = $_POST['price'];
	$catName = $_POST['catName'];
	$itemQTY = $_POST['itemQTY'];
    $sql = "sql";
	$errmsg = " no error";
	
 	$itemPicture = "";
	if($_FILES['file']['error'] == 0) {
		$file = $_FILES['file']['tmp_name'];
		$f = fopen($file, "r");
		$itemPicture = fread($f, filesize($file));
		$itemPicture = addslashes($itemPicture);
		fclose($f);
	}
	if(empty($itemName)){
    	$errmsg = " Can not add item 2";
    }
	else if(empty($price)){
    	$errmsg = " Can not add item 3";
    }
	else if(empty($catName)){
    	$errmsg = " Can not add item 4";
    }else if(empty($itemQTY)){
    	$errmsg = " Can not add item 5";
    }
	$sql = "INSERT INTO Item (itemID, itemName, price, itemQTY, Category_catId, itemPicture) VALUES ('$itemID' , '$itemName','$price' , '$itemQTY', 1, '$itemPicture');";
	echo $sql;
		@mysql_query($sql) or die(mysql_error());
		//mysql_close($objConnect);
		header("Refresh:3;url=itemlist.php");		
	
	

echo "$itemID $itemName $catName $itemQTY $price";

echo $sql;
echo "$errmsg";
    exit;
}
?>


<center>
  <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
    
  <table width="465" height="267" border="0">
  <tr>
    <td colspan="2"><strong>Add Item</strong></td>
    </tr>
  <tr>
    <td width="119">Item ID</td>
    <td><input type="text" name="itemID" id="itemID" />      <label for="itemID"></label></td>
    </tr>
  <tr>
    <td>Item name</td>
    <td><input type="text" name="itemName" id="itemName" />      <label for="itemName"></label></td>
    </tr>
  <tr>
    <td>Price</td>
    <td><input type="text" name="price" id="price" />      <label for="price"></label></td>
    </tr>
  <tr>
    <td>Item category</td>
    <td width="117"><select name="catName" id="catName">
      <option>New Arrival</option>
      <option>Most Purchase</option>
    </select></td>
    </tr>
  <tr>
    <td>Item QTY</td>
    <td><input type="text" name="itemQTY" id="itemQTY" />      <label for="itemQTY"></label></td>
    </tr>
  <tr>
    <td>Item picture</td>
    <td><label for="itemPicture">
      <input type="file" name="file" size="30" id="file" />
    </label></td>
    </tr>
  <tr>
    <td>QR Image</td>
    <td><input type="file" name="QRImage" size="30" id="QRImage" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Add" id="Add" value="Add" />
      <input type="submit" name="clare" id="clare" value="Clear" /></td>
    </tr>
</table>
<p>&nbsp;</p>
</form>
</center>

</body>
</html>
